﻿using DevExpress.XtraGrid.Demos.util;
using Luna小店.DTO;
using Luna小店.DTO.尖山;
using Luna小店.model;
using Luna小店.service;
using Luna小店.UC.款式异常;
using Luna小店.原型;
using mendian;
using System;
using System.Collections.Generic;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace Luna小店.UC.门店下单.DTO
{
    /// <summary>
    /// 订单DTO
    /// </summary>
    public class OrderDto
    {
        #region 属性
        public Enum订单类型 orderSalesType { get; set; }//订单类型
        public String id { get; set; }
        public String customerId { get; set; }
        public String customerName { get; set; }
        public String addressId { get; set; }
        public String customerCountId { get; set; }
        public String shopId { get; set; }
        public String shopName { get; set; }
        public String styleId { get; set; }
        public String orderNo { get; set; }
        public Double orderNumber { get; set; }
        public DateTime orderDate { get; set; }
        public String styleSizeCd { get; set; }
        public String styleNameCn { get; set; }
        public String styleYear { get; set; }
        public String styleSeason { get; set; }
        public String refStyleId { get; set; }
        public String styleFabricId { get; set; }
        public String materialNameCn { get; set; }
        public String materialCode { get; set; }  //面料号
        public String materialColor { get; set; }
        public String stylePublishCategoryCd { get; set; }
        public String styleCategoryCd { get; set; }
        public String styleFitCd { get; set; }
        public String styleSizeGroupCd { get; set; }
        public String styleDressCategory { get; set; }
        public String styleDesignType { get; set; }
        public enumOrderType orderType { get; set; }
        public String remarks { get; set; }//备注
        public String styleMakeType { get; set; }//制作工艺
        public Image picture { get; set; }
        public StyleAccessoryItemsDTO styleAccessoryItemsDTO { get; set; }//辅料
        public String saveStyleAccessoryItemsDTO { get; set; }//Json辅料保存
        public String sessionId { get; set; }
        public String kashiyamaOrderNo { get; set; }
        public List<备注图片> remarksPicture { get; set; } = new List<备注图片>();//备注图片
        public String fromId { get; set; }  //样品下单FormId
        public List<MeasureItemDTO> measureItemDTOS { get; set; } = new List<MeasureItemDTO>();//尺寸
        #endregion

        #region 枚举
        public enum enumOrderType { 服装定制 = 1, 标准款 = 2, 受托加工 = 3 }
        #endregion

        #region 设计点和量体制信息
        public List<DTODesignPoints> dtoDesignPoints { get => dto设计点s; } //设计点
        public DtoSize dtoSize { get => dto尺寸; } //尺寸

        private List<DTODesignPoints> dto设计点s = new List<DTODesignPoints>();   //  设计点
        private DtoSize dto尺寸;  //  尺寸
        #endregion

        #region 坚山美国订单回执用
        public 坚山美国订单回执数据 OrderReceiptData { get; set; }//Order回执数据
        #endregion
        /// <summary>
        /// 新增订单转为一览
        /// </summary>
        /// <param name="dto定制下单"></param>
        public OrderDto(Dto定制下单 dto定制下单) {
            this.fromId = dto定制下单.formId; //样品下单FormId
            this.id = new FunctionHelper().Uuid;
            this.dto设计点s = dto定制下单.Dto设计点s; //  设计点信息
            this.dto尺寸 = dto定制下单.Dto尺寸; //  尺寸信息

            //  款式和面料信息
            this.refStyleId = dto定制下单.Style_Id;
            this.styleFabricId = dto定制下单.SYTLE_FABRIC_ID;
            this.materialCode = dto定制下单.materialCode;
            this.materialNameCn = dto定制下单.materialNameCn;

            this.styleCategoryCd = dto定制下单.STYLE_CATEGORY_CD;
            this.styleFitCd = dto定制下单.STYLE_FIT_CD;
            this.styleSizeGroupCd = dto定制下单.STYLE_SIZE_GROUP_CD;

            this.styleSizeCd = dto定制下单.STYLE_SIZE_CD;
            this.orderNumber = dto定制下单.ORDER_NUMBER;
            this.orderType = enumOrderType.服装定制;
            this.remarks = dto定制下单.REMARKS;
            this.styleMakeType = dto定制下单.STYLE_MAKE_TYPE;
            this.sessionId = dto定制下单.sessionId;
            try
            {
                this.picture = FabricService.GetMianLiaoFile(this.styleFabricId);
            }
            catch
            {
                this.picture = FunctionHelper.getSSHIRT();
            }
            if (!String.IsNullOrEmpty(this.refStyleId))
            {
                this.buildStyle();  //  更新款式信息
            }
            //this.buildMaterialInfo();   //  更新面料信息
            if (!String.IsNullOrEmpty(dto定制下单.STYLE_NAME_CN))
            {
                this.styleNameCn = dto定制下单.STYLE_NAME_CN;
            }
            this.remarksPicture = dto定制下单.备注图片s;
            
        }

        public OrderDto(Dto定制下单 dto定制下单,String ORDER_ID)
        {
            this.id = ORDER_ID;
            this.dto设计点s = dto定制下单.Dto设计点s; //  设计点信息
            this.dto尺寸 = dto定制下单.Dto尺寸; //  尺寸信息

            //  款式和面料信息
            this.refStyleId = dto定制下单.Style_Id;
            this.styleFabricId = dto定制下单.SYTLE_FABRIC_ID;

            this.styleCategoryCd = dto定制下单.STYLE_CATEGORY_CD;
            this.styleFitCd = dto定制下单.STYLE_FIT_CD;
            this.styleSizeGroupCd = dto定制下单.STYLE_SIZE_GROUP_CD;

            this.styleSizeCd = dto定制下单.STYLE_SIZE_CD;
            this.orderNumber = dto定制下单.ORDER_NUMBER;
            this.orderType = enumOrderType.服装定制;

            try
            {
                this.picture = FabricService.GetMianLiaoFile(this.styleFabricId);
            }
            catch
            {
                this.picture = FunctionHelper.getSSHIRT();
            }
            this.buildStyle();  //  更新款式信息
            this.buildMaterialInfo();   //  更新面料信息
        }

        /// <summary>
        /// 更新款式信息
        /// </summary>
        private void buildStyle() {
            DataRow dataRow = StyleService.generateStyleInfo(this.refStyleId);
            this.styleNameCn = dataRow["STYLE_NAME_CN"].ToString();
            this.styleYear = dataRow["SYTLE_YEAR"].ToString();
            this.styleSeason = dataRow["SYTLE_SEASON"].ToString();
            this.stylePublishCategoryCd = dataRow["STYLE_PUBLISH_CATEGORY_CD"].ToString();
            this.styleDressCategory = dataRow["STYLE_DRESS_CATEGORY"].ToString();
            this.styleDesignType = dataRow["STYLE_DESIGN_TYPE"].ToString();
        }

        /// <summary>
        /// 更新面料信息
        /// </summary>
        private void buildMaterialInfo() {
            DataRow dataRow = FabricService.generateMaterialInfo(this.styleFabricId);
            this.materialNameCn = dataRow["MATERIAL_NAME_CN"].ToString();
            this.materialColor = dataRow["MATERIAL_COLOR"].ToString();
        }
        /// <summary>
        /// 辅料信息注入
        /// </summary>
        /// <param name="dto辅料"></param>
        /// <returns></returns>
        public OrderDto build辅料信息(StyleAccessoryItemsDTO dto辅料)
        {
            this.styleAccessoryItemsDTO = dto辅料;
            return this;
        }
        /// <summary>
        /// 辅料的orderid注入（保存订单用）
        /// </summary>
        /// <param name="orderid"></param>
        /// <returns></returns>
        public OrderDto build辅料OrderID(String orderid)
        {
            this.styleAccessoryItemsDTO.buildOrderid(orderid);
            this.saveStyleAccessoryItemsDTO = FunctionHelper.JsonSerialization(this.styleAccessoryItemsDTO.styleAccessoryDetails);
            return this;
        }
        /// <summary>
        /// 美国坚山Excel设计点注入
        /// </summary>
        /// <param name="Style"></param>
        /// <param name="设计点"></param>
        /// <returns></returns>
        public OrderDto build设计点fromExcel(String Style, DTO订单页 dTO订单页)
        {
            #region 共用
            DTO坚山美国订单导入 dTO = new DTO坚山美国订单导入().build设计点名称对应().build设计点类型名称对应();
            DTO默认设计点 dTO默认设计点;
            foreach (KeyValuePair<String, String> kvp in dTO订单页.map)
            {
                if (!String.IsNullOrWhiteSpace(kvp.Value) && !kvp.Key.Contains("(5)") && !kvp.Key.Contains("(6)") && !kvp.Key.Contains("(17)") && !kvp.Key.Contains("(9)"))
                {
                    try
                    {
                        dTO默认设计点 = dTO.Dic设计点类型名称对应[kvp.Key];
                        this.dto设计点s.Add(new DTODesignPoints().buildFromExcel(dTO默认设计点.ItemCd, dTO默认设计点.ItemValue, dTO.Dic设计点名称对应[kvp.Value]));
                    }
                    catch { }
                }
            }
            foreach (KeyValuePair<String, String> kvp in dTO订单页.map)
            {
                if (kvp.Key.Contains("(5)"))
                {
                    if (kvp.Value.Contains("Yes"))
                    {
                        this.dto设计点s.Add(new DTODesignPoints().buildFromExcel("4SCON", "KSCC", ""));
                    }
                }
                else if (kvp.Key.Contains("(6)"))
                {
                    if (kvp.Value.Contains("Y"))
                    {
                        foreach (DTODesignPoints dto设计点 in this.dto设计点s)
                        {
                            if (dto设计点.itemValue.Contains("4SCU"))
                            {
                                if (dto设计点.optionValue.Contains("KSC8"))
                                {
                                    dto设计点.optionValue = "KSC82";
                                }
                                else if (dto设计点.optionValue.Contains("KSC3"))
                                {
                                    dto设计点.optionValue = "KSC32";
                                }
                                else if (dto设计点.optionValue.Contains("KSC6"))
                                {
                                    dto设计点.optionValue = "KSC62";
                                }
                                else if (dto设计点.optionValue.Contains("KSC7"))
                                {
                                    dto设计点.optionValue = "KSC72";
                                }
                            }
                        }
                    }
                }
                else if (kvp.Key.Contains("(17)"))
                {
                    foreach (DTODesignPoints dto设计点 in this.dto设计点s)
                    {
                        if (dto设计点.itemValue.Contains("4SFP"))
                        {
                            if (dto设计点.optionValue.Contains("KSFP9"))
                            {
                                dto设计点.optionValue = "KSFP10";
                            }
                            else if (dto设计点.optionValue.Contains("KSFP8"))
                            {
                                dto设计点.optionValue = "KSFP11";
                            }
                        }
                    }
                }
                else if (kvp.Key.Contains("(9)")) //刺绣内容
                {
                    this.dto设计点s.Add(new DTODesignPoints().buildFromExcel("SHIRT_MONOGRAM_SCO", "4SMT", kvp.Value));
                }
                else if (kvp.Key.Contains("(1)"))//后背款
                {
                    if (kvp.Value.Contains("1"))
                    {
                        dTO订单页.FIT_CD = "FIT_BODY_TYPE-KS01";
                    }
                    if (kvp.Value.Contains("2"))
                    {
                        dTO订单页.FIT_CD = "FIT_BODY_TYPE-KS02";
                    }
                    if (kvp.Value.Contains("3"))
                    {
                        dTO订单页.FIT_CD = "FIT_BODY_TYPE-KS03";
                    }
                    if (kvp.Value.Contains("4"))
                    {
                        dTO订单页.FIT_CD = "FIT_BODY_TYPE-KS04";
                    }
                }
            }
            this.dto设计点s.Add(new DTODesignPoints().buildFromExcel("SHIRT_DESIGN_SAT", "4SAT", "KSATB1"));//钉扣方法 机缝十字
            this.dto设计点s.Add(new DTODesignPoints().buildFromExcel("SHIRT_DESIGN_SBO", "4SBO", "KSBOY"));//插签  活插签
            this.dto设计点s.Add(new DTODesignPoints().buildFromExcel("SHIRT_MONOGRAM_SMS", "4SMS", "MS6"));//刺绣尺寸 6mm 普通
            this.dto设计点s.Add(new DTODesignPoints().buildFromExcel("SHIRT_MONOGRAM_WMP", "WMP", "WMP01"));//水洗标位置 左侧缝距底摆10cm
            this.dto设计点s.Add(new DTODesignPoints().buildFromExcel("SHIRT_MONOGRAM_TM", "TM", "TM01"));//商标  客供
            this.dto设计点s.Add(new DTODesignPoints().buildFromExcel("SHIRT_MONOGRAM_TMP", "TMP", "TMP01"));//商标位置 台领下2cm四面订
            this.dto设计点s.Add(new DTODesignPoints().buildFromExcel("SHIRT_MONOGRAM_FLP", "FLP", "FLP01"));//面料标位置 下前立距底摆3cm
            this.dto设计点s.Add(new DTODesignPoints().buildFromExcel("SHIRT_DESIGN_SSK", "4SSK", "KSS3"));//领：普通S1   袖头：普通S1
            #endregion

            switch (Style)
            {
                case "HD": this.dto设计点s.Add(new DTODesignPoints().buildFromExcel("SHIRT_DESIGN_SSL", "4SSL", "KSSL1"));
                    break;
                case "HF": this.dto设计点s.Add(new DTODesignPoints().buildFromExcel("SHIRT_DESIGN_SSL", "4SSL", "KSSL1"));
                    break;
                case "HH": this.dto设计点s.Add(new DTODesignPoints().buildFromExcel("SHIRT_DESIGN_SSL", "4SSL", "KSHSL2"));
                    break;
            }
            return this;
        }
        /// <summary>
        /// 美国坚山Excel基本信息注入
        /// </summary>
        /// <param name="Style"></param>
        /// <param name="dTO订单页"></param>
        /// <param name="dTOHDHF"></param>
        /// <returns></returns>
        public OrderDto build基本信息fromExcel(String Style, DTO订单页 dTO订单页, DTOMeasurements dTOHDHF)
        { 
            #region 共用
            面料DTO 面料dto = FabricService.Get面料DtoByCD新(dTO订单页.FabricNumber);
            this.id = new FunctionHelper().Uuid;
            this.orderNumber = 1;
            this.styleSizeCd = "EGS_GROUP_SIZE-" + dTOHDHF.Size;
            this.styleYear = "2020";
            this.styleSeason = "SEASON-SEASON_10";
            this.styleFabricId = 面料dto.Id;
            this.materialNameCn = 面料dto.面料名称;
            this.materialColor = 面料dto.面料颜色;
            this.stylePublishCategoryCd = "PUBLISH_STYLE_CATEGORY-MShirt";
            this.styleCategoryCd = "STYLE_CATEGORY-SHIRT";
            this.styleFitCd = dTO订单页.FIT_CD;
            this.styleSizeGroupCd = "GROUP_SIZE-EGS_GROUP_SIZE";
            this.styleDressCategory = "STYLE_DRESS_CATEGORY-FORMAL_SUIT";
            this.styleDesignType = "STYLE_DESIGN_TYPE-668";
            this.orderType = enumOrderType.服装定制;
            this.remarks = null;
            this.styleMakeType = "4SMA-4M";
            #endregion
            switch (Style)
            {
                case "HD":
                    this.styleNameCn = "HD坚山美国普通长袖";
                    this.refStyleId = "7776599";
                    break;
                case "HF":
                    this.styleNameCn = "HF坚山美国礼服款长袖";               
                    this.refStyleId = "7776601";
                    break;
                case "HH":
                    this.styleNameCn = "HH坚山美国普通半袖";
                    this.refStyleId = "7776600";
                    break;
            }
            return this;
        }
        /// <summary>
        /// 美国坚山Excel尺寸注入
        /// </summary>
        /// <param name="dTOMeasurements"></param>
        /// <returns></returns>
        public OrderDto build尺寸fromExcel(DTOMeasurements dTOMeasurements, String FIT_CD)
        {
            this.dto尺寸 = new DtoSize(dTOMeasurements,FIT_CD);
            this.measureItemDTOS = this.dto尺寸.measureItemDTOS;
            return this;
        }
        public OrderDto()
        {

        }

        /// <summary>
        /// 订单数据注入除了客户信息
        /// </summary>
        /// <param name="dTOTest"></param>
        /// <param name="dTOHDHF"></param>
        /// <param name="dTOHH"></param>
        /// <returns></returns>
        public OrderDto build订单fromExcel(DTO订单页 dTO订单页, DTOMeasurements dTOHDHF, DTOMeasurements dTOHH)
        {
            switch (dTO订单页.Item)
            {
                case "HD":
                    this.build设计点fromExcel("HD", dTO订单页);
                    this.build基本信息fromExcel("HD", dTO订单页, dTOHDHF);
                    this.build尺寸fromExcel(dTOHDHF, this.styleFitCd);
                    break;
                case "HH":
                    this.build设计点fromExcel("HH", dTO订单页);
                    this.build基本信息fromExcel("HH", dTO订单页, dTOHH);
                    this.build尺寸fromExcel(dTOHH,this.styleFitCd);
                    break;
                case "HF":
                    this.build设计点fromExcel("HF", dTO订单页);
                    this.build基本信息fromExcel("HF", dTO订单页, dTOHDHF);
                    this.build尺寸fromExcel(dTOHDHF, this.styleFitCd);
                    break;
            }
            return this;
        }
        /// <summary>
        /// 回执数据注入
        /// </summary>
        /// <param name="dt"></param>
        /// <returns></returns>
        public OrderDto build坚山美国回执数据(DataTable dt,String sheetName)
        {
            this.OrderReceiptData = new 坚山美国订单回执数据(dt).buildSheetName(sheetName);
            return this;
        }
        /// <summary>
        /// kashiyamaOrderNo注入
        /// </summary>
        /// <param name="kashiyamaOrderNo"></param>
        /// <returns></returns>
        public OrderDto buildkashiyamaOrderNo(String kashiyamaOrderNo)
        {
            this.kashiyamaOrderNo = kashiyamaOrderNo;
            return this;
        }
        /// <summary>
        /// 订单类型
        /// </summary>
        /// <param name="enum"></param>
        /// <returns></returns>
        public OrderDto build订单类型(Enum订单类型 @enum)
        {
            this.orderSalesType = @enum;
            return this;
        }
    }

    public class InspectSizeDTO
    {
        public String id { get; set; }//id
        public int index { get; set; }//序号
        public String itemNameCn { get; set; }//大分类名称
        public Double garmentSize { get; set; }//成衣尺寸
        public Double inValue { get; set; }    //  加值
        public Double outValue { get; set; }   //  减值
        public String parentId { get; set; }//父id
        public bool ifPass { get; set; }//是否通过
        public bool hasFitValue { get; set; }//是否人尺寸
        public bool hasGarmentSize { get; set; }//是否成衣尺寸
        public bool hasHalf { get; set; }//是否1/2

        public InspectSizeDTO(string id, int index, string itemNameCn, double garmentSize, string parentId, bool ifPass, bool hasFitValue, bool hasGarmentSize, bool hasHalf)
        {
            this.id = id;
            this.index = index;
            this.itemNameCn = itemNameCn;
            this.garmentSize = garmentSize;
            this.parentId = parentId;
            this.ifPass = ifPass;
            this.hasFitValue = hasFitValue;
            this.hasGarmentSize = hasGarmentSize;
            this.hasHalf = hasHalf;
        }

        public InspectSizeDTO()
        {

        }
    }
}
